﻿using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;
using Android.Webkit;
using ZXAPP;

namespace ZXXFAPP.Droid
{
    [Activity(Label = "BPMES", Icon = "@drawable/appicon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            ZXing.Net.Mobile.Forms.Android.Platform.Init();
            WebView.SetWebContentsDebuggingEnabled(true);            

            LoadApplication(new App());
        }
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
        [Obsolete]
        public override void OnBackPressed()
        {
            AndroidX.AppCompat.App.AlertDialog.Builder builder = new AndroidX.AppCompat.App.AlertDialog.Builder(this);
            builder.SetMessage("确定要退出程序吗？");
            builder.SetPositiveButton("确定", (sender, args) =>
            {
                // 用户点击确定按钮，执行退出应用程序的逻辑
                Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
            });
            builder.SetNegativeButton("取消", (sender, args) =>
            {
                // 用户点击取消按钮，不执行退出应用程序的逻辑
            });

            AndroidX.AppCompat.App.AlertDialog dialog = builder.Create();
            dialog.Show();

        }
    }
}